package com.luo.chengrui.module.sa.enums;

import java.util.Arrays;
import java.util.Optional;

public enum YesOrNoEnum {
    NO(0, "否"),
    YES(1, "是");


    private Integer id;
    private String name;

    YesOrNoEnum(Integer code, String name) {
        this.id = code;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static YesOrNoEnum getByCode(Integer id) {
        Optional<YesOrNoEnum> optional = Arrays.stream(YesOrNoEnum.values()).filter(item -> id == item.id).findFirst();
        if (optional.isPresent()) {
            return optional.get();
        }

        throw new RuntimeException(String.format("编码%s存在枚举【GlobalStatusEnum】中不存在", id));
    }
}
